#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : micah
# @time    : 2023/12/2 16:06
# @function: 音频下载
# @version :

import os
import requests

url_list = [
    'https://downsc.chinaz.net/Files/DownLoad/sound1/202303/y1646.mp3',
    'https://downsc.chinaz.net/Files/DownLoad/sound1/202303/y1645.mp3',
    'https://downsc.chinaz.net/Files/DownLoad/sound1/202303/y1643.mp3',
    'https://downsc.chinaz.net/Files/DownLoad/sound1/202303/y1642.mp3',
    'https://downsc.chinaz.net/Files/DownLoad/sound1/202303/y1641.mp3'
]
path = '音频/'
if not os.path.exists(path):
    os.mkdir(path)


for url in url_list:
    # 定义一个headers字典，其中包含了User-Agent信息，用于伪装浏览器，防止被网站屏蔽。
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
    }
    # session对象可以通过发送多个请求来保持会话状态，例如保持登录状态等。
    session = requests.session()
    # 使用session对象的get方法发送HTTP请求，并将url和headers作为参数传入
    response = session.get(url, headers=headers)

    # 保存数据
    name ="音频/" + url.split('/')[-1]
    with open(name, 'wb') as f:
        f.write(response.content)

